package com.tju.shortlink.admin.controller;


import com.tju.shortlink.admin.common.convention.result.Result;
import com.tju.shortlink.admin.common.convention.result.Results;
import com.tju.shortlink.admin.dto.req.ShortLinkGroupSaveReqDTO;
import com.tju.shortlink.admin.dto.req.ShortLinkGroupSortReqDTO;
import com.tju.shortlink.admin.dto.req.ShortLinkGroupUpdateReqDTO;
import com.tju.shortlink.admin.dto.resp.ShortLinkGroupRespDTO;
import com.tju.shortlink.admin.service.IGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mxl
 * @since 2024-07-05
 */
@Tag(name = "短链接分组相关接口")
@RestController
@RequestMapping("/api/short-link/admin/v1/group")
@RequiredArgsConstructor
public class GroupController {

    private final IGroupService groupService;

    @Operation(summary = "新增短链接分组")
    @PostMapping
    public Result<Void> saveGroup(@RequestBody ShortLinkGroupSaveReqDTO requestParam){
        groupService.saveGroup(requestParam.getName());
        return Results.success();
    }

    @Operation(summary = "查询短链接分组")
    @GetMapping()
    public Result<List<ShortLinkGroupRespDTO>> listGroup(){
        return Results.success(groupService.listGroup());
    }

    @Operation(summary = "修改短链接分组名称")
    @PutMapping()
    public Result<Void> updateGroup(@RequestBody ShortLinkGroupUpdateReqDTO requestParam){
        groupService.updateGroup(requestParam);
        return Results.success();
    }

    @Operation(summary = "删除短链接分组")
    @DeleteMapping
    public Result<Void> deleteGroup(@RequestParam String gid){
        groupService.deleteGroup(gid);
        return Results.success();
    }

    @Operation(summary = "短链接分组排序功能")
    @PostMapping("sort")
    public Result<Void> sortGroup(@RequestBody List<ShortLinkGroupSortReqDTO> requestParam){
        groupService.sortGroup(requestParam);
        return Results.success();
    }

}
